package com.example.springboot_test.easyexcel.model;

import cn.hutool.core.util.StrUtil;
import com.example.springboot_test.common.poi.constant.POIExcelConstant;
import com.example.springboot_test.easyexcel.model.common.SheetRangeModel;
import lombok.Getter;

/**
 * 下拉框信息类
 *
 * @author xudongmaster
 */
@Getter
public class SpinnerModel extends SheetRangeModel {
    /**
     * 下拉框数据
     */
    private String[] spinnerData;

    private SpinnerModel() {
    }

    /**
     * 生成下拉框信息
     *
     * @param sheetName     sheet页名称
     * @param colIndex      列索引
     * @param startRowIndex 开始行索引
     * @param spinnerData   下拉框数据
     * @return 拉框信息
     */
    public static SpinnerModel createSpinnerModel(String sheetName, Integer colIndex, Integer startRowIndex, String[] spinnerData) {
        return createSpinnerModel(sheetName, colIndex, colIndex, startRowIndex, POIExcelConstant.ROW_INDEX_MAX, spinnerData);
    }

    /**
     * 生成下拉框信息
     *
     * @param sheetName     sheet页名称
     * @param startColumnIndex 开始列索引
     * @param endColumnIndex   结束列索引
     * @param startRowIndex 开始行索引
     * @param endRowIndex   结束行索引
     * @param spinnerData   下拉框数据
     * @return 拉框信息
     */
    public static SpinnerModel createSpinnerModel(String sheetName, Integer startColumnIndex, Integer endColumnIndex, Integer startRowIndex, Integer endRowIndex, String[] spinnerData) {
        SpinnerModel spinnerModel = new SpinnerModel();
        //sheet页名称
        spinnerModel.sheetName = StrUtil.isNotBlank(sheetName) ? sheetName : POIExcelConstant.SHEET_NAME_DEFAULT;
        //开始列索引
        startColumnIndex = startColumnIndex != null ? startColumnIndex : POIExcelConstant.COL_INDEX_MIN;
        spinnerModel.startColumnIndex = startColumnIndex;
        //结束列索引
        endColumnIndex = endColumnIndex != null ? endColumnIndex : startColumnIndex;
        spinnerModel.endColumnIndex = endColumnIndex;
        //开始行索引
        startRowIndex = startRowIndex != null ? startRowIndex : POIExcelConstant.ROW_INDEX_MIN;
        spinnerModel.startRowIndex = startRowIndex;
        //结束行索引
        endRowIndex = endRowIndex != null ? endRowIndex : POIExcelConstant.ROW_INDEX_MAX;
        spinnerModel.endRowIndex = endRowIndex;
        //下拉框数据
        spinnerData = spinnerData != null ? spinnerData : new String[]{};
        spinnerModel.spinnerData = spinnerData;
        return spinnerModel;
    }


}